package com.mf.all.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.micrometer.common.util.StringUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import com.mf.all.entity.dto.DtoWarehouse;
import com.mf.all.entity.req.search.SearchReqWarehouse;
import com.mf.all.mapper.MapperWarehouse;
import com.mf.all.service.ServiceWarehouse;


@Service
public class ImplServiceWarehouse extends ServiceImpl<MapperWarehouse, DtoWarehouse> implements ServiceWarehouse {


    @Override
    public LambdaQueryWrapper<DtoWarehouse> fillParams(SearchReqWarehouse params) {
        final LambdaQueryWrapper<DtoWarehouse> wrapper = loadQw();
        if (StringUtils.isNotBlank(params.getKey())) {
            wrapper.and(w -> {
                w.like(DtoWarehouse::getWName, params.getKey())
                        .or()
                        .like(DtoWarehouse::getDescription, params.getKey());
            });
        }
        wrapper.eq(ObjectUtils.isNotEmpty(params.getStatus()), DtoWarehouse::getStatus, params.getStatus())
                .eq(StringUtils.isNotEmpty(params.getType()), DtoWarehouse::getType, params.getType());
        return wrapper;
    }

}